<?php

namespace App\Jobs;

use App\Models\Appointment;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class CancelAppointmentOrder implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $ids;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($ids)
    {
        $this->ids = $ids;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
    	Log::info('取消预约订单任务开始，预约订单Id号为'.$this->ids);
	    $Info = Appointment::where('id',$this->ids)->first();
	    Log::info($Info->toArray());
	    if($Info->status == 1){
		    Log::info('该订单号'.$this->ids."已经被理发师接单！");
	    	return ;
	    }
	    $Info->status = 3;
	    $Info->cancel_type =2;
	    $Info->remark = '系统自动取消';
	    $Info->save();
	    Log::info('取消预约订单任务结束'.$this->ids);
    }
}
